import {addComment, queryById, queryComments, blogAction, deleteComments} from './service';

export default {
  namespace: 'blogInfo',
  state: {
    data: {},
  },
  effects: {
    *queryById({ payload }, { call, put }) {
      const response = yield call(queryById, payload);
      yield put({
        type: 'save',
        payload: response,
      });
      return response;
    },
    *queryComment({ payload }, { call, put }) {
      return yield call(queryComments, payload);
    },
    *addComment({ payload }, { call, put }) {
      return yield call(addComment, payload);
    },
    *blogAction({ payload }, { call, put }) {
      return yield call(blogAction, payload);
    },
    *deleteComments({ payload }, { call, put }) {
      return yield call(deleteComments, payload);
    },
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },
  },
};
